package com.future.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.future.mapper.DrivingDriverMapper;
import com.future.mapper.DrivingStatisMapper;
import com.future.po.DrivingDriver;
import com.future.po.DrivingStatis;
import com.future.service.DrivingDriverService;
import com.future.service.DrivingStatisService;
import com.future.vo.DrivingDriverVo2;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class DrivingDriverServiceImpl extends ServiceImpl<DrivingDriverMapper, DrivingDriver> implements DrivingDriverService {

    @Autowired
    private DrivingDriverMapper drivingDriverMapper;

    @Override
    public List<DrivingDriverVo2> statisticBehaveByDate(String startDate, String endDate,Integer id) {
        List<DrivingDriver> drivingDrivers = drivingDriverMapper.statisticBehaveByDate(startDate, endDate ,id);
        ArrayList<DrivingDriverVo2> drivingDriverVoList = new ArrayList<>();
        for (DrivingDriver drivingDriver : drivingDrivers
        ) {
            DrivingDriverVo2 drivingDriverVo2 = new DrivingDriverVo2();
            BeanUtils.copyProperties(drivingDriver, drivingDriverVo2);


            int sum = drivingDriver.getYawning() +
                    drivingDriver.getCellphone() +
                    drivingDriver.getEyesClosed() +
                    drivingDriver.getBothHandsLeavingWheel() +
                    drivingDriver.getHeadLowered() +
                    drivingDriver.getNoFaceMask() +
                    drivingDriver.getNotBucklingUp() +
                    drivingDriver.getNotFacingFront() +
                    drivingDriver.getSmoke();
            drivingDriverVo2.setSum(sum);
            drivingDriverVoList.add(drivingDriverVo2);
        }

        return drivingDriverVoList;

    }
}
